<template>
  <div  ref="editorRef">editor</div>
</template>

<script>
import E from 'wangeditor'
export default {
  props: {
    value: {
      type: String
    }
  },
  methods: {
    initEditor () {
      const editor = new E(this.$refs.editorRef)
      editor.config.onchange = (newHtml) => {
        console.log(newHtml)
        this.$emit('input', newHtml)
      }
      editor.create()
      editor.txt.html(this.value)
      this.$watch(this.value, () => {
        editor.txt.html(this.value)
      })
    }
  },
  mounted () {
    this.initEditor()
  }
}
</script>
